import java.util.Stack;

public class LC_150 {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        int right = 0;
        int left = 0;
        for(int i = 0; i < tokens.length; i++){
            if(tokens[i].equals("+")){
                right = stack.pop();
                left =  stack.pop();
                stack.push(left + right);

            }else if(tokens[i].equals("-")){
                right = stack.pop();
                left =  stack.pop();
                stack.push(left - right);

            }else if(tokens[i].equals("*")){
                right = stack.pop();
                left =  stack.pop();
                stack.push(left * right);
            }else if(tokens[i].equals("/")){
                right = stack.pop();
                left =  stack.pop();
                stack.push(left / right);
            }else{
                int j = Integer.parseInt(tokens[i]);
                stack.push(j);
            }
        }
        return stack.pop();
    }
}
